$(document).ready(function() {
    Highcharts.setOptions({
        global: {
            useUTC: false
        },
        colors:['#F0382B','#28A1F6','#27D834']
    });
    j = 0;
    seriesname = new Array();
    Data_min = 0,Data_max = 0,Data_avg = 0,Data_mdev = 0;
    $('#ping').click(function () {
        splinename = $("#Local").val();
        alert(splinename);
        var params = {};
        if(seriesname.length != 0){
            for(i = 0;i < seriesname.length;i++){
                if(seriesname[i] == splinename){
                    alert("该IP已经使用");
                    status = 0;
                    break;
                }
            }
            if(status == 1){
                seriesname[j] = splinename;
                params.ipAddress = seriesname[j];
                $.ajax({
                    type: "post",
                    url: "http://localhost:8080/getPingTimeAnalysis.action",
                    data:params,
                    dataType: "json",

                    success: function (res, status) {
                        Data_min = parseFloat(res.min);
                        Data_max = parseFloat(res.max);
                        Data_avg = parseFloat(res.avg);
                        Data_mdev = parseFloat(res.mdev);
                        chart.addSeries({name:seriesname[j],data:[Data_min,Data_max,Data_avg,Data_mdev]});
                        j = j + 1;
                    },
                    error: function (res, status, xhr) {
                        alert(res);
                        alert(status);
                        alert(xhr);
                    }
                });
            }
        }
        else {
            seriesname[j] = splinename;
            params.ipAddress = seriesname[j];
            $.ajax({
                type: "post",
                url: "http://localhost:8080/getPingTimeAnalysis.action",
                data:params,
                dataType: "json",

                success: function (res, status) {
                    Data_min = parseFloat(res.min);
                    Data_max = parseFloat(res.max);
                    Data_avg = parseFloat(res.avg);
                    Data_mdev = parseFloat(res.mdev);
                    chart.addSeries({name:seriesname[j],data:[Data_min,Data_max,Data_avg,Data_mdev]});
                    j = j + 1;
                },
                error: function (res, status, xhr) {
                    alert(res);
                    alert(status);
                    alert(xhr);
                }
            });
        }
    });
    var chart;
    chart = new Highcharts.Chart({
        chart: {
            renderTo: 'histogram',
            type: 'column'
        },
        title: {
            text: '<b>综合应用设计</b>'
        },
        subtitle: {
            text: '总结柱状图'
        },
        xAxis: {
            categories: [
                'min',
                'mix',
                'avg',
                'mdev'
            ],
            crosshair: true
        },
        yAxis: {
            min: 0,
            title: {
                text: 'value'
            }
        },
        tooltip: {
            headerFormat: '<span style="font-size:15px"><b>{point.key}</b></span><table>',
            pointFormat: '<tr><td style="color:{series.color};padding:0"></b>{series.name}: </td>' +
            '<td style="padding:0"><b>{point.y:.1f}</b></td></tr>',
            useHTML: true
        },
        plotOptions: {
            column: {
                pointPadding: 0.2,
                borderWidth: 0
            }
        },
        credits: {
            enabled: false
        },
        series: []
    });
});

